import { defineStore } from "pinia";
import type { UserState } from "@/stores/interface/index";

export default defineStore("UserStore", {
  state: (): UserState => ({
    token: "",
    userInfo: {}
  }),
  getters: {},
  actions: {
    setToken(token: string) {
      this.token = token;
    },
    setUserInfo(userInfo: UserState["userInfo"]) {
      this.userInfo = userInfo;
    },
    clearUserInfo() {
      this.token = "";
      this.userInfo = {};
    }
  },
  persist: {
    key: "userInfo",
    storage: localStorage
  }
});
